package com.ruoyi.common.utils;

/**
 * Created On : 2024/3/30.
 * Author : xuliang
 * Description: SummarySheetHandler
 * <p>
 */

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;

import java.util.List;

public class SummarySheetHandler implements SheetWriteHandler {
    @Override
    public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {

    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        Workbook workbook = writeWorkbookHolder.getWorkbook();
        Sheet sheet = workbook.getSheetAt(0);
        sheet.setColumnWidth(0,10000);
        sheet.setColumnWidth(1,4000);
        sheet.setColumnWidth(2,4000);
        sheet.setColumnWidth(3,4000);
        sheet.setColumnWidth(4,4000);
        sheet.setColumnWidth(5,4000);
        sheet.setColumnWidth(6,2400);
        sheet.setColumnWidth(7,7000);

        //Row row2 = sheet.getRow(1);
        //row2.setHeightInPoints(100);

        //Row row = sheet.createRow(rowIndex);
        //row.setHeightInPoints(20); // 设置行高为20个像素

        //设置标题
        Row row0 = sheet.createRow(0);
        row0.setHeight((short) 600);
        Cell title = row0.createCell(0);
        title.setCellValue("2023年项目动态总成本及盈亏分析表");
        CellStyle titleStyle = workbook.createCellStyle();
        titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        titleStyle.setAlignment(HorizontalAlignment.CENTER);
        Font font = workbook.createFont();
        font.setBold(true);
        font.setFontHeight((short) 400);
        titleStyle.setFont(font);
        title.setCellStyle(titleStyle);
        sheet.addMergedRegionUnsafe(new CellRangeAddress(0, 1, 0, 7));
        sheet.addMergedRegionUnsafe(new CellRangeAddress(19, 19, 1, 6));
        sheet.addMergedRegionUnsafe(new CellRangeAddress(20, 20, 1, 6));
        sheet.addMergedRegionUnsafe(new CellRangeAddress(21, 21, 1, 6));
        sheet.addMergedRegionUnsafe(new CellRangeAddress(22, 22, 1, 6));

    }

}
